<template>
{{#if ctrl.psSysPFPlugin}}
    {{> @macro/plugins/widget/widget-use.hbs appPlugin=ctrl.psSysPFPlugin}}
{{else}}
    <AppForm ref="searchForm" :name="model.codeName" :class="classNames" :data="store.data" style="{{#if ctrl.width}}width: {{ctrl.width}}px;{{/if}}{{#if ctrl.height}}height: {{ctrl.height}}px;{{/if}}">
        <div class="control-content app-control-searchform__content">
            <AppRow class="app-control-searchform__left">
{{#if ctrl.noTabHeader}}
    {{#each ctrl.psDEFormPages as | ctrlPage | }}
        {{#each ctrlPage.psDEFormDetails as | formDetail | }}
            {{> @macro/widgets/form-detail/include-form.hbs type=formDetail.detailType item=formDetail}}
        {{/each }}
    {{/each}}
    {{else}}
            <van-tabs class="app-control-form__page">
        {{#each ctrl.psDEFormPages as | ctrlPage | }}
                {{> @macro/widgets/form-detail/include-form.hbs type=ctrlPage.detailType item=ctrlPage}}
        {{/each}}
            </van-tabs>
{{/if}}
            </AppRow>
        </div>
        {{#and (neq ctrl.formStyle 'SEARCHBAR') (neq ctrl.searchButtonStyle 'NONE')}}
        <div class="app-control-footer footer__buttons">
            <AppButton type="primary"   @click="handleSearch" >\{{$t('widget.searchform.search','搜索')}}</AppButton>
            <AppButton @click="handleReset">\{{$t('widget.searchform.reset','重置')}}</AppButton>
        </div>
        {{/and}}    
    </AppForm>
{{/if}}
</template>
<script setup lang="ts">
// 基于template/src/widgets/\{{appEntities}}/\{{ctrls@SEARCHFORM}}-searchform/\{{spinalCase ctrl.codeName}}-searchform.vue.hbs生成
{{> @macro/plugins/widget/widget-import.hbs ctrl=ctrl}}
import { AppCol } from '@/components/common/col';
import { AppRow } from '@/components/common/row';
import { AppForm, AppFormPage, AppFormGroup, AppFormTabPage, AppFormItem, AppFormButton, AppFormDruipart, AppFormIframe, AppFormRaw } from '@components/widgets/form';
import { useNavParamsBind, useEventBind, getCtrlClassNames, handleComponentAction } from '@/hooks/use-ctrl';
import { IContext, IEvent, IParam, ICtrlDataAction, ISearchFormAbility, ISearchFormControllerParams, ISearchFormStore, SearchFormActionType, SearchFormController, ILoadingHelper, createUUID, IViewCtx } from '@/core';
import { {{pascalCase ctrl.name}}ControlVO } from './{{spinalCase ctrl.codeName}}-searchform-vo';
import { model } from './{{spinalCase ctrl.codeName}}-searchform-model';
import SearchFormService from "@/core/modules/ctrl-service/searchform-service";

{{> @macro/widgets/ctrl/ctrl-props.hbs
    props="openView?: Function;
    newView?: Function;
    actions: ICtrlDataAction;
    "
}}

{{> @macro/common/emit.hbs name="ctrl" actionType="SearchFormActionType" ability="ISearchFormAbility"}}

const { keyPSAppDEField, majorPSAppDEField } = model;

let searchForm = ref<any>(null);

const ctrlService = new SearchFormService<{{pascalCase ctrl.name}}ControlVO>({{pascalCase ctrl.name}}ControlVO, model.entityCodeName);

const controlID = createUUID();

const params: ISearchFormControllerParams<SearchFormActionType, ISearchFormAbility> = {
    name: props.name,
    model,
    evt,
    controlID,
    actions: props.actions,
    openView: props.openView,
    newView: props.newView,
    closeView: props.closeView,    
    ctrlService: ctrlService,
    pViewCtx: props.pViewCtx,
    formValidate: async () => { return await searchForm.value.formValidate() },
    handler: (data: ISearchFormStore) => { return reactive(data); }
};
// 表单控制器
const controller = new SearchFormController(params);
useNavParamsBind(controller, props);

const store: ISearchFormStore = controller.getStore();

const classNames = computed(() => {
  return getCtrlClassNames(model, props);
});


{{#and (neq ctrl.formStyle 'SEARCHBAR') (neq ctrl.searchButtonStyle 'NONE')}}
const handleSearch = (event: MouseEvent) => {
    controller.search();
}
const handleReset = (info: any) => {
    controller.reset();
}
{{/and}}
onMounted(() => {
    controller.ctrlMounted();
});
onUnmounted(() => {
    controller.ctrlDestroy();
})
</script>